home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: Q: Terminating program at EOF
- Date: 7 Jan 1996 06:22:00 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4cnoq8$4fv@news.iag.net>
- References: <4cn66j$5r0@fnpx20.fnal.gov>
- NNTP-Posting-Host: pm2-orl7.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <4cn66j$5r0@fnpx20.fnal.gov>, sfield@fnpx20.fnal.gov says...
- <snip>
- >I've written a program that does the job, but it doesn't stop when it reaches
- >the end of the file. The program will write out the reformatted file, but it
- >appends a lot of "extra" characters to the end of the file and only stops
- when
- >I break out of it.
- <snip>
- >#include <stdio.h>
- >#define MAX_WORD_LENGTH 80 /* max length of word in input */
- >
- >main()
- >{
- > int line_length, /* max length of line in output */
- > curr_line_length = 0, /* # of chars printed so far in curr line */
- > word_length; /* length of current word */
- > char word[ MAX_WORD_LENGTH+1];/* buffer to read word +1 for terminating
- > '\0' */
- > char c_old=' ',c_new=' '; /* check for newlines with chars */
- <snip>
- >
- >/* while((c_new=fgetc(fptr_read))!=EOF){ */ /* old method for removing EOF
- bug */
- > while(c_new!=EOF){ /* new method, still doesn't
- work */
-
- There is absolutely no guarantee that EOF can be represented by a char. This
- is why the ansi character i/o functions use int instead of char (check the
- declaration/prototype for fgetc). Try changing c_new to int and see, if the
- problem clears up.
-
- PS) you need to add a return statement to the end of main.
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-